package name.matthewgreet.example8.action; import javax.servlet.http.HttpSession; import org.apache.struts2.ActionSupport; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import name.matthewgreet.example8.dto.PrimeMinisterDTO; import name.matthewgreet.example8.form.PrimeMinisterForm; import name.matthewgreet.example8.util.PrimeMinisterCompositeCache; import name.matthewgreet.example8.view.PartySelectBoxDisplay; import name.matthewgreet.strutscommons.action.AbstractViewActionSupport; import name.matthewgreet.strutscommons.util.ListCache; import name.matthewgreet.strutscommons.util.NA; /** * Displays page to edit a Prime Minister record. */ @InterceptorRef("ViewStack") @Results({ @Result(name="list", type="redirectAction", params = {"namespace", "/", "actionName", "ViewPrimeMinisterList"}), @Result(name=ActionSupport.SUCCESS, location="/pages/PrimeMinister.jsp") }) public class ViewPrimeMinisterAction extends AbstractViewActionSupport { private static final long serialVersionUID = -7979376337555804889L; private String refresh; private int listSize; private Integer recordNo; private PrimeMinisterForm form; private PartySelectBoxDisplay partySelectBoxDisplay; @Action("/ViewPrimeMinister") @Override public String execute() throws Exception { PrimeMinisterDTO primeMinister; ListCache<NA,Integer,PrimeMinisterDTO> listCache; HttpSession session; session = getBrowserTabSession(); listCache = PrimeMinisterCompositeCache.getInstance(session).getMasterListCache(); if (listCache.getReload()) { // No list due to expired session return "list"; } if (refresh != null) { listCache.forceReload(); } if (recordNo != null) { listCache.setSelectedIndex(recordNo - 1); } listSize = listCache.getListSize(); recordNo = listCache.getSelectedIndex() + 1; primeMinister = listCache.getSelected(); if (form == null) { form = new PrimeMinisterForm(primeMinister); } formatForms(); partySelectBoxDisplay = new PartySelectBoxDisplay(); partySelectBoxDisplay.setSelectedValue(form.getParty()); return SUCCESS; } public String getRefresh() { return refresh; } public void setRefresh(String refresh) { this.refresh = refresh; } public int getListSize() { return listSize; } public Integer getRecordNo() { return recordNo; } public void setRecordNo(Integer recordNo) { this.recordNo = recordNo; } public PrimeMinisterForm getForm() { return form; } public PartySelectBoxDisplay getPartySelectBoxDisplay() { return partySelectBoxDisplay; } }